package _4弹出框;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class MyFrame extends JFrame implements ActionListener{
	
	public MyFrame()
	{
		this.setLayout(null);
		
		JButton btn1 = new JButton("彈出框1");
		btn1.setBounds(10,10,100,40);
		this.add(btn1);
		btn1.addActionListener(this);
		
		JButton btn2 = new JButton("彈出框2");
		btn2.setBounds(110,10,100,40);
		this.add(btn2);
		btn2.addActionListener(this);
		JButton btn3 = new JButton("彈出框3");
		btn3.setBounds(210,10,100,40);
		this.add(btn3);
		btn3.addActionListener(this);
		JButton btn4 = new JButton("彈出框4");
		btn4.setBounds(310,10,100,40);
		this.add(btn4);
		btn4.addActionListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent e) 
	{
		switch(e.getActionCommand())
		{
		case "彈出框1":
			JOptionPane.showMessageDialog(this,"helllo world!");
			break;
		case "彈出框2":
//			int result = JOptionPane.showConfirmDialog(this, "是否刪除?");
			int result = JOptionPane.showConfirmDialog(this, "是否刪除?","刪除",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE);
			System.out.println(result);
			// 0 是
			// 1 否
			// 2 取消
			// -1 關閉
			
			break;
		case "彈出框3":
			String name = JOptionPane.showInputDialog("請輸入用戶名:");
			System.out.println(name);
			break;
		}
		
	}

}
